﻿using System.Web;

namespace dPet.Web.Hospital.ViewModels
{
	using dPet.Application.DataObjects;
	using dPet.Application.Services;
	using Hangerd.Components;
	using Hangerd.Mvc.Authentication;

	public class LoginStaffModel
	{
		private static IAccountService AccountService
		{
			get { return LocalServiceLocator.GetService<IAccountService>(); }
		}

		private const string LOGIN_STAFF_KEY = "LOGIN_STAFF_KEY";

		public static StaffDto Current
		{
			get
			{
				if (HttpContext.Current != null)
				{
					var staff = HttpContext.Current.Items.Contains(LOGIN_STAFF_KEY)
						? HttpContext.Current.Items[LOGIN_STAFF_KEY] as StaffDto : null;

					if (staff == null)
					{
						var currentStaffId = LoginHelper.GetUserId();

						staff = AccountService.GetStaff(currentStaffId);

						if (staff != null)
						{
							HttpContext.Current.Items.Add(LOGIN_STAFF_KEY, staff);
						}
					}

					return staff;
				}

				return null;
			}
		}
	}
}
